package domain.entities;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * CdaMolecula entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "cda_molecula", catalog = "bms")
public class CdaMolecula implements java.io.Serializable, Comparable<CdaMolecula> {

	// Fields

	private Integer id;
	private Droga droga;
	private Involucrado involucrado;
	private Date fechaEnviado;
	private Date fechaRecibido;
    private String comment;
    private Date expiration;
    private Date signature;

	// Constructors

	/** default constructor */
	public CdaMolecula() {
	}

	/** minimal constructor */
	public CdaMolecula(Droga droga, Involucrado involucrado) {
		this.droga = droga;
		this.involucrado = involucrado;
	}

	/** full constructor */
	public CdaMolecula(Droga droga, Involucrado involucrado, Date fechaEnviado,
			Date fechaRecibido) {
		this.droga = droga;
		this.involucrado = involucrado;
		this.fechaEnviado = fechaEnviado;
		this.fechaRecibido = fechaRecibido;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "DROGAid", nullable = false)
	public Droga getDroga() {
		return this.droga;
	}

	public void setDroga(Droga droga) {
		this.droga = droga;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "INVESTIGADORid", nullable = false)
	public Involucrado getInvolucrado() {
		return this.involucrado;
	}

	public void setInvolucrado(Involucrado involucrado) {
		this.involucrado = involucrado;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "fechaEnviado", length = 10)
	public Date getFechaEnviado() {
		return this.fechaEnviado;
	}

	public void setFechaEnviado(Date fechaEnviado) {
		this.fechaEnviado = fechaEnviado;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "fechaRecibido", length = 10)
	public Date getFechaRecibido() {
		return this.fechaRecibido;
	}

	public void setFechaRecibido(Date fechaRecibido) {
		this.fechaRecibido = fechaRecibido;
	}

    @Column(name = "comment")
    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }


    @Temporal(TemporalType.DATE)
    @Column(name = "expiration", length = 10)
    public Date getExpiration() {
        return expiration;
    }

    public void setExpiration(Date expiration) {
        this.expiration = expiration;
    }

    @Override
    public int compareTo(CdaMolecula o) {
        return this.expiration.compareTo(o.getExpiration());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CdaMolecula)) return false;

        CdaMolecula that = (CdaMolecula) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "signature", length = 10)
    public Date getSignature() {
        return signature;
    }

    public void setSignature(Date signature) {
        this.signature = signature;
    }
}